import axios from 'axios'
//处理长id
import JSONbig  from 'json-bigint'

const request = axios.create({
  baseURL: 'http://ttapi.research.itcast.cn/',

  transformRequest:[function(data){
    try{
      return JSONbig.parse(data)
    }catch(err){
      return data
    }
  }]
})

request.interceptors.request.use(function (config) {
  const user = JSON.parse(window.localStorage.getItem('user'))
  if(user){
    config.headers.Authorization=`Bearer ${user.token}`
  }
  return config;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});


export default request